﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CCWin;

namespace BS_2
{
    public partial class Form_OpenPrj : CCWin.Skin_DevExpress
    {
        Form1 f;
        public Form_OpenPrj(Form1 f)
        {
            this.f = f;
            this.ShowInTaskbar = false;
            InitializeComponent();
        }

        private void showPrjinfo(string name)
        {
            string sql = "select * from project where prjname='" + name + "'";
            DataTable dt = DataAccess.Get_DataTable(sql, "prj");
            prjname.Text = dt.Rows[0]["prjname"].ToString();
            prjcreator.Text = dt.Rows[0]["prjcreator"].ToString();
            prjdate.Text = Convert.ToDateTime(dt.Rows[0]["prjdate"].ToString()).ToString("yyyy-MM-dd");
            prjsource.Text = dt.Rows[0]["prjsource"].ToString();

            sql = "select dot_id,x,y from project_domain where prjcode=" + dt.Rows[0]["prjcode"].ToString();
            DataTable dtdomain = DataAccess.Get_DataTable(sql, "prjdomain");
            dataGridView1.DataSource = dtdomain;
            dataGridView1.Columns[0].Width = 60;
        }


        private void frmPrjOpen_Load(object sender, EventArgs e)
        {
            string sql = "select prjname from project order by prjname";
            DataTable dt = DataAccess.Get_DataTable(sql, "prj");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                CCWin.SkinControl.SkinListBoxItem item = new CCWin.SkinControl.SkinListBoxItem(dt.Rows[i][0].ToString());
                prjList.Items.Add(item);
            }
            prjList.SelectedIndex = 0;
            showPrjinfo(prjList.Items[0].ToString());

        }

        private void prjList_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void submit_Click(object sender, EventArgs e)
        {
            if (prjList.Items.Count > 0)
            {
                Globale.project_name = prjname.Text;
                string sql = "select prjcode from project where prjname='" + Globale.project_name + "'";
                Globale.project_code = Convert.ToInt32(DataAccess.Get_Row1_Col1_Value(sql));
            }
            f.treeView1.Nodes.Clear();
            f.TreeViewShowNodeDataSet(Globale.project_code);
            //MessageBox.Show("ok!");
        }

        private void prjList_Click(object sender, EventArgs e)
        {
            if (prjList.Items.Count > 0)
            {
                string name = prjList.SelectedItem.ToString();
                showPrjinfo(name);
            }
        }

        private void Close_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
